﻿using System;
using System.IO;

namespace txcloud.sdk
{
    using ExcelConfig;
    using ExcelConfig.Config;
    using ExcelConfig.StoreAPI;
    using txcloud.sdk.Core;

    public class TxCloudSDK
    {
        public static string ConfigPath = AppConfig.Text(TxCloudSDKHelper.LOCALCONFIG_PATH);
        public static string ConfigName = AppConfig.Text(TxCloudSDKHelper.CFGSTORE_CONFIGNAME);
        public static string ConfigZone = AppConfig.Text(TxCloudSDKHelper.CFGSTORE_CONFIGZONE);
        public static AppConfigFile Config { get; internal set; }
        public static TxCred TxCred { get; internal set; }
        static TxCloudSDK()
        {
            if (!Directory.Exists(ConfigPath)) Directory.CreateDirectory(ConfigPath);
            var filepath = Path.Combine(ConfigPath, ConfigName+ExcelConfigSetting.CONFIG_SUFFIX);
            if (!File.Exists(filepath)) ConfigStoreAPI.DownloadToFile(AppConfig.Text(TxCloudSDKHelper.CFGSTORE_CONFIGZONE), ConfigName, filepath);
            Config = new AppConfigFile(ConfigPath, ConfigName);
            TxCred = new TxCred(TxCloudSDK.Config.Text("SecretId") ,TxCloudSDK.Config.Text("SecretKey"));
        }
    }
}
